<template>
    <div id="app">
        <choose-item v-for="(item,index) in list" :key="index"
            :obj="item"
            @chooseFun="change"
        ></choose-item>
    </div>
</template>

<script>
import axios from 'axios'
import chooseItem from './components/chooseItem'
/*
    beforeCreate

    created  请求数据  
    
    this.$nextTick().then(() => {
        //操作dom
    })

    beforeMount

    mounted  操作dom

    beforeUpdate

    updated

    beforeDestory

    destoryed

    父向子  props  对象 数组 数字 字符串 布尔值 

    子向父  $emit（事件名）  < @事件名="函数"
*/ 

export default {
    name: 'App',
    data(){
        return {
            list:[],
            chooseObj:{}
        }
    },
    components:{
        chooseItem
    },
    created(){
        axios.get('/api/list').then((res) => {
            if(res.data.code === 1){
                this.list = res.data.data;
                this.list.forEach(item => {
                    this.$set(this.chooseObj,item.Subject,item.Content[0].Type);
                })
                console.log(this.chooseObj);
            }
        }).catch((error) => {
            console.warn(error)
        })
    },
    methods:{
        change(subject,type){
            this.chooseObj[subject] = type;
            console.log(this.chooseObj);
        }
    }

}
</script>

<style>
@import "./assets/common.css";
#app{
    width:100%;
    height: 100%;
    overflow: scroll;
}
</style>
